<template>
  <basic-container>
    <el-form ref="form" :model="form" :rules="rules" label-width="80px">
      <el-row type="flex" class="row-bg" justify="end">
        <el-form-item>
          <el-button type="primary" @click="handleAgree">提交</el-button>
          <!-- <el-button type="danger" @click="handleDisagree">驳回</el-button> -->
          <el-button @click="handleCancel">关闭</el-button>
        </el-form-item>
      </el-row>
      <el-card shadow="hover">
        <div slot="header">
          <span>矛盾信息</span>
        </div>
        <el-row>
          <el-col :span="8">
            <el-form-item label="所属网格">
              <el-input :disabled="true" v-model="form.gridName"/>
            </el-form-item>
          </el-col>
         <el-col :span="8">
            <el-form-item label="上报人">
              <el-input :disabled="true" v-model="form.flow.assigneeName"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="事件名称">
              <el-input :disabled="true" v-model="form.eventName"/>
            </el-form-item>
          </el-col>
           <el-col :span="8">
            <el-form-item label="发生日期">
              <el-input :disabled="true" v-model="form.happenDate"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="发生地点">
              <el-input :disabled="true" v-model="form.happenPlace"/>
            </el-form-item>
          </el-col>
           <el-col :span="8">
            <el-form-item label="事件规模">
              <el-input :disabled="true" v-model="form.eventScale"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="事件类别">
              <el-input :disabled="true" v-model="form.eventCategory"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="涉及人数">
              <el-input :disabled="true" v-model="form.numberInvolved"/>
            </el-form-item>
          </el-col>
          
           <el-col :span="8">
            <el-form-item label="涉及单位">
              <el-input :disabled="true" v-model="form.relatedUnits"/>
            </el-form-item>
          </el-col>
           <el-col :span="24">
            <el-form-item label="事件描述">
              <el-input :disabled="true" type="textarea" v-model="form.eventDescription"/>
            </el-form-item>
          </el-col>
           <el-col :span="8">
            <el-form-item label="主要当事人姓名">
              <el-input :disabled="true" v-model="form.name"/>
            </el-form-item>
          </el-col>
           <el-col :span="8">
            <el-form-item label="当事人证件">
              <el-input :disabled="true" v-model="form.identificationCode"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="当事人证件号码">
              <el-input :disabled="true" v-model="form.idCard"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="当事人性别">
              <el-input :disabled="true" v-model="form.sex"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="当事人民族">
              <el-input :disabled="true" v-model="form.nation"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="当事人学历">
              <el-input :disabled="true" v-model="form.education"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="当事人类别">
              <el-input :disabled="true" v-model="form.personnelCategory"/>
            </el-form-item>
          </el-col>
           <el-col :span="16">
            <el-form-item label="当事人居住详址">
              <el-input :disabled="true" v-model="form.detailAddress"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
             <el-form-item label="处理方式">
              <el-select v-model="handleType" clearable  placeholder="请选择">
                <el-option
                  v-for="item in handleTypeOptions"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
             </el-form-item>
          </el-col>
          <el-col :span="24">
             <el-form-item label="批复意见">
          <el-input type="textarea" v-model="form.comment"/>
        </el-form-item>
          </el-col>


        </el-row>
      </el-card>
      <el-card shadow="hover">
        <div slot="header">
          <span>流程信息</span>
        </div>
        <el-row type="flex" class="row-bg">
          <el-timeline>
            <el-timeline-item :key="flow.id" :timestamp="flow.createTime" v-for="flow in flowList" placement="top">
              <el-card shadow="hover">
                <p>{{flow.assigneeName}} 在 [{{flow.createTime}}] 开始处理 [{{flow.historyActivityName}}] 环节</p>
                <p v-if="flow.historyActivityDurationTime!==''">任务历时 [{{flow.historyActivityDurationTime}}]</p>
                <p v-if="flow.comment!==''">批复意见: [{{flow.comment}}]</p>
                <p v-if="flow.endTime!==''">结束时间: [{{flow.endTime}}]</p>
              </el-card>
            </el-timeline-item>
          </el-timeline>
        </el-row>
      </el-card>
      <el-card shadow="hover">
        <div slot="header">
          <span>流程跟踪</span>
        </div>
        <el-row type="flex" class="row-bg">
          <img :src="src" alt="design">
        </el-row>
      </el-card>
    </el-form>
  </basic-container>
</template>

<script>
  import {historyFlowList, disputeDetail} from "@/api/work/process";
  import {completeTask} from "@/api/ninebasic/dispute/conflictsResolve";
 // import {getDeptTree} from "@/api/system/dept";

  export default {
    
    data() {
      return {
        taskId: '',
        businessId: '',
        processInstanceId: '',
        src: '',
        flowList: [],
        form: {
          flow: {
            assigneeName: '',
          },
          gridName: '',
          eventName: '',
          happenDate: '',
          happenPlace: '',
          eventScale: '',
          eventCategory: '',
          numberInvolved: '',
          eventDescription: '',
          relatedUnits: '',
          identificationCode: '',
          idCard: '',
          sex: '',
          nation: '',
          education: '',
          personnelCategory: '',
          detailAddress: '',
         
        },
         handleTypeOptions: [{
            value: '01',
            label: '办结'
          }, {
            value: 'community',
            label: '上报社区村'
          }, {
            value: 'streetCenter',
            label: '上报镇街'
          },],
          handleType: '',
      }
    },
    created() {
      this.init();
    },
    beforeRouteUpdate(to, from, next) {
      // 在当前路由改变，但是该组件被复用时调用
      // 举例来说，对于一个带有动态参数的路径 /foo/:id，在 /foo/1 和 /foo/2 之间跳转的时候
      // 由于会渲染同样的 Foo 组件，因此组件实例会被复用。而这个钩子就会在这个情况下被调用
      // 可以访问组件实例 `this`
      if (to.fullPath !== from.fullPath) {
        next();
        this.init();
      }
    },
    methods: {
      init() {
        //动态获取机构tree
        // getDeptTree().then(res => {
        //   const column = this.findObject(this.option.column, "parentId");
        //   column.dicData = res.data.data;
        // });
        this.taskId = this.$route.params.taskId;
        this.processInstanceId = this.$route.params.processInstanceId;
        this.businessId = this.$route.params.businessId;
        this.src = `/api/smart-flow/process/diagram-view?processInstanceId=${this.$route.params.processInstanceId}`;
        historyFlowList(this.processInstanceId).then(res => {
          console.log(this.processInstanceId);
          const data = res.data;
          if (data.success) {
            this.flowList = data.data;
          }
        })
        disputeDetail(this.businessId).then(res => {
          const data = res.data;
          if (data.success) {
            this.form = data.data;
          }
        })
      },
      handleAgree() {
        if (!this.form.comment) {
          this.$message.warning('请先填写处理意见');
          return;
        }
        if (!this.handleType) {
          this.$message.warning('请先填写处理方式');
          return;
        }
        const params = {
          taskId: this.taskId,
          processInstanceId: this.processInstanceId,
          flag: 'ok',
          comment: this.form.comment,
          handleType: this.handleType,
        };
        completeTask(params).then(res => {
          const data = res.data;
          if (data.success) {
            this.$message.success(data.msg);
            this.$router.$avueRouter.closeTag();
            this.$router.push({path: `/ninebasic/dispute/todo`});
          } else {
            this.$message.error(data.msg || '提交失败');
          }
        })
      },
      handleCancel() {
        this.$router.$avueRouter.closeTag();
        this.$router.push({path: `/ninebasic/dispute/todo`});
      }
    }
  }
</script>
<style>
.el-form-item__content{
   margin-left: 150px ! important;
}
.el-form-item__label {
  width: 150px ! important;
}
</style>